package com.bjpowernode.app;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import java.util.Iterator;
import java.util.List;

public class MyApp6 {
    public static void main(String[] args) {
        TreeNode<Integer> nodeSrc = new TreeNode<>(1, 0, "src", 0);
        TreeNode<Integer> nodeMain = new TreeNode<>(2, 1, "main", 0);
        TreeNode<Integer> nodeTest = new TreeNode<>(3, 1, "test", 1);
        TreeNode<Integer> nodeMain1 = new TreeNode<>(4, 2, "main1", 1);
        TreeNode<Integer> nodeMain2 = new TreeNode<>(5, 2, "main2", 1);
        TreeNode<Integer> nodeMain3 = new TreeNode<>(6, 2, "main3", 1);

        List<TreeNode<Integer>> nodeList = CollUtil.newArrayList();
        nodeList.add(nodeSrc);
        nodeList.add(nodeMain);
        nodeList.add(nodeTest);

        Iterator<TreeNode<Integer>> iterator = nodeList.iterator();
        while (iterator.hasNext()) {
            TreeNode<Integer> treeNodeTemp = iterator.next();
            System.out.println(treeNodeTemp.getName());

            List<Tree<Integer>> treeNodes = TreeUtil.build(nodeList, treeNodeTemp.getId());
            if (treeNodes != null) {
                for (Tree<Integer> treeNode : treeNodes) {
                    System.out.println(treeNode.getName());
                }
            }
            iterator.remove();

        }

    }
}
